/*
 * Copyright (C) 2011 JiangHongTiao <jjurco.sk_gmail.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
 * PrisonersDilemma.java
 *
 * Created on May 26, 2011, 3:16:11 PM
 */
package sk.lieskove301.jianghongtiao.liaad.prisoner.gui;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.SpinnerNumberModel;
import sk.lieskove301.jianghongtiao.liaad.prisoner.Arena;
import sk.lieskove301.jianghongtiao.liaad.prisoner.ga.crossover.CrossoverEnum;
import sk.lieskove301.jianghongtiao.liaad.prisoner.ga.mutation.MutationEnum;
import sk.lieskove301.jianghongtiao.liaad.prisoner.ga.selection.Selection;
import sk.lieskove301.jianghongtiao.liaad.prisoner.ga.selection.SelectionEnum;
import sk.lieskove301.jianghongtiao.liaad.prisoner.gene.GeneEnum;
import sk.lieskove301.jianghongtiao.liaad.prisoner.memory.ForgettingEnum;
import sk.lieskove301.jianghongtiao.liaad.prisoner.payoff.PayoffCartel;
import sk.lieskove301.jianghongtiao.liaad.prisoner.payoff.PayoffCooperateWin;
import sk.lieskove301.jianghongtiao.liaad.prisoner.statistics.StatisticStore;
import sk.lieskove301.jianghongtiao.liaad.prisoner.statistics.charts.ShowStatistics;
import sk.lieskove301.jianghongtiao.liaad.prisoner.strategy.DefaultStrategy;
import sk.lieskove301.jianghongtiao.liaad.prisoner.strategy.Strategy;
import sk.lieskove301.jianghongtiao.liaad.prisoner.strategy.StrategyEnum;

/**
 *
 * @author JiangHongTiao <jjurco.sk_gmail.com>
 */
public class PrisonersDilemma extends javax.swing.JFrame {

    /** Creates new form PrisonersDilemma */
    public PrisonersDilemma() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jStrategies = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        jSelection = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        jCrossover = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        jMutation = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        approxSelSize = new javax.swing.JSpinner();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jMemories = new javax.swing.JList();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jGenes = new javax.swing.JList();
        jPanel4 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        numberOfAgents = new javax.swing.JSpinner();
        jLabel7 = new javax.swing.JLabel();
        numberOfYears = new javax.swing.JSpinner();
        jLabel8 = new javax.swing.JLabel();
        numberOfDays = new javax.swing.JSpinner();
        jButton2 = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        probabilityOfDetection = new javax.swing.JSpinner();
        jLabel10 = new javax.swing.JLabel();
        cartelProfit = new javax.swing.JSpinner();
        jLabel11 = new javax.swing.JLabel();
        sizeOfFine = new javax.swing.JSpinner();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Settings"));

        jLabel1.setText("Strategies");

        jStrategies.setModel(new DefaultComboBoxModel(StrategyEnum.values()));
        jStrategies.setToolTipText("Select Strategy");
        jStrategies.setName("strategies"); // NOI18N

        jLabel2.setText("Best agent selection type");

        jSelection.setModel(new DefaultComboBoxModel(SelectionEnum.values()));

        jLabel3.setText("Crossover type");

        jCrossover.setModel(new DefaultComboBoxModel(CrossoverEnum.values()));

        jLabel4.setText("Mutation type");

        jMutation.setModel(new DefaultComboBoxModel(MutationEnum.values()));

        jLabel5.setText("Approximate selection size");

        approxSelSize.setModel(new SpinnerNumberModel(new Double(0.4), new Double(0.01), new Double(1), new Double(0.05)));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel1)
                    .addComponent(jStrategies, 0, 160, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(approxSelSize, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jSelection, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jCrossover, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jMutation, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap())
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jCrossover, jLabel1, jLabel2, jLabel3, jLabel4, jMutation, jSelection, jStrategies});

        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jMutation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(jLabel3)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jCrossover, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jSelection, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jStrategies, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(approxSelSize, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Possible Memory Types"));

        jMemories.setModel(new DefaultComboBoxModel(ForgettingEnum.values()));
        jMemories.addContainerListener(new java.awt.event.ContainerAdapter() {
            public void componentAdded(java.awt.event.ContainerEvent evt) {
                jMemoriesComponentAdded(evt);
            }
        });
        jScrollPane1.setViewportView(jMemories);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 161, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Possible Gene Types"));

        jGenes.setModel(new DefaultComboBoxModel(GeneEnum.values()));
        jScrollPane2.setViewportView(jGenes);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 234, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 161, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        jButton1.setText("Initiate Fight");
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton1MouseClicked(evt);
            }
        });

        jLabel6.setText("Number of agents");

        numberOfAgents.setModel(new SpinnerNumberModel(100, 10, 1000, 1));

        jLabel7.setText("Number of years of fight");

        numberOfYears.setModel(new SpinnerNumberModel(10, 3, 10000, 1));

        jLabel8.setText("Number of days");

        numberOfDays.setModel(new SpinnerNumberModel(20, 3, 10000, 1));

        jButton2.setText("Deterministic results");
        jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                deterministicResults(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(numberOfAgents, javax.swing.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel7)
                    .addComponent(numberOfYears, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(numberOfDays, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton1)
                        .addGap(18, 18, 18)
                        .addComponent(jButton2)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel4Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel6, jLabel7, jLabel8, numberOfAgents, numberOfDays, numberOfYears});

        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                .addGroup(jPanel4Layout.createSequentialGroup()
                    .addComponent(jLabel7)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(numberOfYears, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel4Layout.createSequentialGroup()
                    .addComponent(jLabel6)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(numberOfAgents, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel4Layout.createSequentialGroup()
                    .addComponent(jLabel8)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(numberOfDays, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jButton1)
                        .addComponent(jButton2))))
        );

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Cartel Payoff matrix"));
        jPanel5.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel9.setText("Probability of detection");
        jPanel5.add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(6, 21, -1, -1));

        probabilityOfDetection.setModel(new SpinnerNumberModel(0.01, 0, 1, 0.01));
        jPanel5.add(probabilityOfDetection, new org.netbeans.lib.awtextra.AbsoluteConstraints(6, 41, 122, -1));

        jLabel10.setText("Cartel profit");
        jPanel5.add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(6, 71, 124, -1));

        cartelProfit.setModel(new SpinnerNumberModel(1000.0, Double.MIN_VALUE, Double.MAX_VALUE, 10));
        jPanel5.add(cartelProfit, new org.netbeans.lib.awtextra.AbsoluteConstraints(6, 91, 124, -1));

        jLabel11.setText("Size of fine");
        jPanel5.add(jLabel11, new org.netbeans.lib.awtextra.AbsoluteConstraints(6, 121, 124, -1));

        sizeOfFine.setModel(new SpinnerNumberModel(200.0, Double.MIN_VALUE, Double.MAX_VALUE, 10));
        jPanel5.add(sizeOfFine, new org.netbeans.lib.awtextra.AbsoluteConstraints(6, 141, 124, -1));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 751, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(12, 12, 12)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, 228, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel5, javax.swing.GroupLayout.Alignment.TRAILING, 0, 200, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private ForgettingEnum[] castForgettingEnum(Object[] objects){
        ForgettingEnum[] result = new ForgettingEnum[objects.length];
        for (int i = 0; i < objects.length; i++) {
            result[i] = (ForgettingEnum) objects[i];
        }
        return result;
    }
    
    private GeneEnum[] castGeneEnum(Object[] objects){
        GeneEnum[] result = new GeneEnum[objects.length];
        for (int i = 0; i < objects.length; i++) {
            result[i] = (GeneEnum) objects[i];
        }
        return result;
    }
    
    
    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
        // TODO add your handling code here:
        if(jMemories.isSelectionEmpty()){
            JOptionPane.showMessageDialog(this, "Select at least one Memory type please.");
            return;
        }
        if(jGenes.isSelectionEmpty()){
            JOptionPane.showMessageDialog(this, "Select at least one Gene type please.");
            return;
        }
        SelectionEnum selectionEnum = (SelectionEnum) jSelection.getSelectedItem();
        Selection selection = selectionEnum.value();
        selection.setAproxSelectionSize((Double)approxSelSize.getModel().getValue());
        
        StrategyEnum strategyEnum = (StrategyEnum) jStrategies.getSelectedItem();
        Strategy strategy = strategyEnum.value();
        
        ForgettingEnum[] forgettingEnums = castForgettingEnum(jMemories.getSelectedValues());
        strategy.setForgetting(forgettingEnums);
        
        CrossoverEnum crossoverEnum = (CrossoverEnum) jCrossover.getSelectedItem();
        strategy.setCrossover(crossoverEnum.value());
        
        MutationEnum mutationEnum = (MutationEnum) jMutation.getSelectedItem();
        strategy.setMutation(mutationEnum.value());
        strategy.setSelection(selection);
        
        GeneEnum[] genes = castGeneEnum(jGenes.getSelectedValues());
        strategy.setPossibleGenes(genes);
        
        strategy.setPayoff(new PayoffCartel((Double)cartelProfit.getModel().getValue(),
                (Double)probabilityOfDetection.getModel().getValue(),
                (Double)sizeOfFine.getModel().getValue()));
//        strategy.setPayoff(new PayoffCooperateWin());
        
        Arena a = new Arena();
        a.setStrategy(strategy);
        a.setNumberOfAgents((Integer)numberOfAgents.getModel().getValue());
        StatisticStore statistics = a.makeFight((Integer)numberOfYears.getModel().getValue(), 
                (Integer)numberOfDays.getModel().getValue());

        ShowStatistics.showAll(statistics);
    }//GEN-LAST:event_jButton1MouseClicked

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        // TODO add your handling code here:
    }//GEN-LAST:event_formWindowOpened

    private void jMemoriesComponentAdded(java.awt.event.ContainerEvent evt) {//GEN-FIRST:event_jMemoriesComponentAdded
        jMemories.setSelectionInterval(jMemories.getMinSelectionIndex(), jMemories.getMaxSelectionIndex());
    }//GEN-LAST:event_jMemoriesComponentAdded

    private void deterministicResults(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_deterministicResults
        Strategy strategy = new DefaultStrategy(80);
        strategy.setForgetting(new ForgettingEnum[]{ForgettingEnum.LearningMemory});
        strategy.setPayoff(new PayoffCartel((Double)cartelProfit.getModel().getValue(),
                (Double)probabilityOfDetection.getModel().getValue(),
                (Double)sizeOfFine.getModel().getValue()));
        
        Arena a = new Arena();
        a.setStrategy(strategy);
        a.setNumberOfAgents((Integer)numberOfAgents.getModel().getValue());
        StatisticStore statistics = a.makeFight((Integer)numberOfYears.getModel().getValue(), 
                (Integer)numberOfDays.getModel().getValue());

        ShowStatistics.showAll(statistics);
    }//GEN-LAST:event_deterministicResults

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new PrisonersDilemma().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JSpinner approxSelSize;
    private javax.swing.JSpinner cartelProfit;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JComboBox jCrossover;
    private javax.swing.JList jGenes;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JList jMemories;
    private javax.swing.JComboBox jMutation;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JComboBox jSelection;
    private javax.swing.JComboBox jStrategies;
    private javax.swing.JSpinner numberOfAgents;
    private javax.swing.JSpinner numberOfDays;
    private javax.swing.JSpinner numberOfYears;
    private javax.swing.JSpinner probabilityOfDetection;
    private javax.swing.JSpinner sizeOfFine;
    // End of variables declaration//GEN-END:variables
}
